<template>
  <ContentWrap>
      <!-- 搜索工作栏 -->
      <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="100px"
      >
      <!-- <el-form-item label="产品型号" prop="type">
            <el-select
              v-model="queryParams.type"
              placeholder="产品型号"
              clearable
              class="!w-240px"
            >
              <el-option
                v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item> -->
      <el-form-item label="产品型号" prop="type">
          <el-input
            v-model="queryParams.type"
            placeholder="请输入产品型号"
            clearable
            class="!w-240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="重量下限(kg)" prop="lowerWeight ">
          <el-input
            v-model="queryParams.lowerWeight "
            placeholder="请输入重量下限(kg)"
            clearable
            class="!w-240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="重量下限(kg)" prop="upperWeight  ">
          <el-input
            v-model="queryParams.upperWeight  "
            placeholder="请输入重量上限(kg)"
            clearable
            class="!w-240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item> -->
        <el-form-item>
          <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
          <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
          <el-button
              type="primary"
              plain
              @click="openForm('create')"
              v-hasPermi="['system:user:create']"
            >
              <Icon icon="ep:plus" /> 新增
            </el-button>
          <!-- <el-button
                type="warning"
                plain
                @click="handleImport"
                v-hasPermi="['system:user:import']"
              >
                <Icon icon="ep:upload" /> 导入
              </el-button>
          <el-button
            type="success"
            plain
            @click="handleExport"
            :loading="exportLoading"
            v-hasPermi="['system:post:export']"
          >
            <Icon icon="ep:download" class="mr-5px" /> 下载模板
          </el-button> -->
        </el-form-item>
      </el-form>
    </ContentWrap>
  <!-- 列表 -->
  <ContentWrap>
      <el-table v-loading="loading" :data="list">
        <el-table-column type="index" label="序号" align="center" width="55" />
        <!-- <el-table-column label="订单编号" align="center" prop="id" /> -->
        <el-table-column label="产品型号" align="center" prop="type" />
        <el-table-column label="重量下限(g)" align="center" prop="lowerWeight" />
        <el-table-column label="重量上限(g)" align="center" prop="upperWeight" />
        
        <el-table-column label="操作" align="center" width="160">
            <template #default="scope">
              <div class="flex items-center justify-center">
                <el-button
                  type="primary"
                  link
                  @click="openForm('update', scope.row.id)"
                >修改
                </el-button>
                <el-button
                  v-hasPermi="['system:menu:delete']"
                  link
                  type="danger"
                  @click="handleDelete(scope.row.id)"
                >
                删除
            </el-button>
              </div>
            </template>
          </el-table-column>
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
    <!-- 用户导入对话框 -->
    <!-- <orderImportForm ref="importFormRef" @success="getList" /> -->
    <!-- 添加或修改 -->
    <weightRulesForm ref="formRef" @success="getList" />
  </template>
  
  <script lang="ts" setup>
  import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  import download from '@/utils/download'
  import * as weightRulesApi from '@/api/hcxly/materialWeightRules/Index'
  import weightRulesForm from './weightRulesForm.vue'
  
  defineOptions({ name: 'materialWeightRules' })
  
  const router = useRouter() // 路由
  const message = useMessage() // 消息弹窗
  const { t } = useI18n() // 国际化
  
  const loading = ref(true) // 列表的加载中
  const total = ref(0) // 列表的总页数
  const list = ref([]) // 列表的数据

  const queryParams = reactive({
    pageNo: 1,
    pageSize: 10,
    id: undefined,
    orderDateReq: [],
    operator : undefined,
    status : undefined
  })
  const queryFormRef = ref() // 搜索的表单
  const exportLoading = ref(false) // 导出的加载中
  
  /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const data = await weightRulesApi.getMaWeightRules(queryParams)
      console.log(data)
      list.value = data.list
      total.value = data.total
    } finally {
      loading.value = false
    }
  }
  
  /** 搜索按钮操作 */
  const handleQuery = () => {
    queryParams.pageNo = 1
    getList()
  }
  
  /** 重置按钮操作 */
  const resetQuery = () => {
    queryFormRef.value.resetFields()
    handleQuery()
  }
  
  /** 导入 */
  // const importFormRef = ref()
  // const handleImport = () => {
  //   importFormRef.value.open()
  // }
  
  /** 导出按钮操作 */
  // const handleExport = async () => {
  //   try {
  //     // 导出的二次确认
  //     await message.exportConfirm()
  //     // 发起导出
  //     exportLoading.value = true
  //     const data = await weightRulesApi.exportSupplier(queryParams)
  //     download.excel(data, '生产订单导入模板.xls')
  //   } catch {
  //   } finally {
  //     exportLoading.value = false
  //   }
  // }

  
  /** 删除按钮操作 */
  const handleDelete = async (id: string) => {
    try {
      // 删除的二次确认
      await message.delConfirm()
      // 发起删除
      await weightRulesApi.deleteMaWeightRules(id)
      message.success(t('common.delSuccess'))
      // 刷新列表
      await getList()
    } catch {}
  }

  /** 添加/修改操作 */
  const formRef = ref()
  const openForm = (type: string, id?: string) => {
    formRef.value.open(type, id)
  }


  /** 初始化 **/
  onMounted(() => {
    getList()
  })
  
  </script>
